package com.itheima.health.controller;

import com.itheima.health.common.MessageConst;
import com.itheima.health.entity.QueryPageBean;
import com.itheima.health.entity.Result;
import com.itheima.health.pojo.CheckGroup;
import com.itheima.health.service.CheckGroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

@RequestMapping("/checkgroup")
@RestController
public class CheckGroupController {

    @Autowired
    private CheckGroupService checkGroupService;


    /**
     * 检查组管理新增
     * @param checkGroup
     * @param checkitemIds
     * @return
     */
    @PostMapping("/add")
    public Result add(@RequestBody CheckGroup checkGroup, @RequestParam List<String> checkitemIds) {
        return checkGroupService.add(checkGroup,checkitemIds);
    }

    /**
     * 检查组分⻚查询
     * @param queryPageBean
     * @return
     */
    @GetMapping("/findPage")
    public Result findPage(QueryPageBean queryPageBean) {
        return checkGroupService.findPage(queryPageBean);
    }

    /**
     * 根据id查询检查组
     * @param id
     * @return
     */
    @GetMapping("/findById")
    public Result findById(@RequestParam Integer id) {
        return checkGroupService.findById(id);
    }

    /**
     * 获取选中的检查项
     * @param id
     * @return
     */
    @GetMapping("/findCheckItemIdsByCheckGroupId")
    public Result findCheckItemIdsByCheckGroupId(@RequestParam Integer id) {
        return checkGroupService.findCheckItemIdsByCheckGroupId(id);
    }

    /**
     * 编辑
     * @param checkGroup
     * @param checkitemIds
     * @return
     */
    @PostMapping("/edit")
    public Result edit(@RequestBody CheckGroup checkGroup, @RequestParam List<String> checkitemIds) {
        return checkGroupService.edit(checkGroup,checkitemIds);
    }

    /**
     * 根据id删除检查组
     * @param id
     * @return
     */
    @PostMapping("/deleteCheckGroupitemById")
    public Result deleteCheckGroupitemById(@RequestParam Integer id) {
        return checkGroupService.deleteCheckGroupitemById(id);
    }

    /**
     * 获取选中的检查组
     * @param id
     * @return
     */
    @GetMapping("/findCheckGroupIdsBySetmealId")
    public Result findCheckGroupIdsBySetmealId(@RequestParam Integer id) {
        return checkGroupService.findCheckGroupIdsBySetmealId(id);
    }

    @GetMapping("/findAll")
    public Result findAll() {
        return checkGroupService.findAll();
    }
}
